﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class ControlUser_ControlBaoCaoDanhSachDonHangPhaiQuetBoSung : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = BCDataCenter.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (MemoryStream filestream = new MemoryStream())
        {

            string contentType = "application/ms-excel";
            string fileName = System.DateTime.Now.ToString("dd/MM/yyyy") + "_BaoCaoDonHangQuetBoSung.xls";
            ASPxPivotGridExporter1.ExportToXls(filestream);
            byte[] buffer = filestream.GetBuffer();
            Response.Clear();
            Response.Buffer = false;
            Response.AppendHeader("Content-Type", contentType);
            Response.AppendHeader("Content-Transfer-Encoding", "binary");
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName);
            Response.BinaryWrite(buffer);
            Response.End();
        }
    }
    protected void btReport_Click(object sender, EventArgs e)
    {
        ASPxPivotGrid1.Fields.Clear();
        Title();
        dt = new ClassExecute.ClassExecute();
        DataTable dataCap = dt.Get_Data_DataTable(str, ref error, "ls_getLaterScannedDoc", CommandType.StoredProcedure,
            new SqlParameter("@userName", Session["username"].ToString()));
        if (dataCap.Rows.Count > 0)
        {
            foreach (DataColumn col in dataCap.Columns)
            {

                ASPxPivotGrid1.Fields.Add(col.ColumnName.ToString(), DevExpress.XtraPivotGrid.PivotArea.RowArea);

            }

            this.ASPxPivotGrid1.DataSource = dataCap;
            this.ASPxPivotGrid1.DataBind();
        }
        else
        {
            uscMsgBox1.AddMessage("Hiện tại không có dữ liệu", uscMsgBox.enmMessageType.Error);
        }
    }
    public void Title()
    {
        if (!ASPxPivotGrid1.Fields.Contains(ASPxPivotGrid1.Fields["Baocao"]))
        {
            ASPxPivotGrid1.Fields.Add("Baocao", DevExpress.XtraPivotGrid.PivotArea.FilterArea);
            ASPxPivotGrid1.Fields["Baocao"].HeaderStyle.BackColor = Color.Yellow;
            ASPxPivotGrid1.Fields["Baocao"].Caption = "Báo cáo nhật ký xuất nhập hàng";
        }

        if (!ASPxPivotGrid1.Fields.Contains(ASPxPivotGrid1.Fields["Time"]))
        {
            ASPxPivotGrid1.Fields.Add("Time", DevExpress.XtraPivotGrid.PivotArea.FilterArea);
            ASPxPivotGrid1.Fields["Time"].HeaderStyle.BackColor = Color.Yellow;
            ASPxPivotGrid1.Fields["Time"].Caption = "Ngày giờ lấy báo cáo : " + DateTime.Now.ToShortDateString() + "  " + DateTime.Now.ToShortTimeString();
        }
    }
}
